#!/bin/sh
# Compile:by-lanse    2018-09-01
route_vlan=`/sbin/ifconfig br0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " " `

## 配置dnsmasq.conf启动规则
grep "storage" /etc/storage/dnsmasq/dnsmasq.conf
if [ $? -eq 0 ]; then
	sed -i '/127.0.0.1/d' /etc/storage/dnsmasq/dnsmasq.conf
	sed -i '/log/d' /etc/storage/dnsmasq/dnsmasq.conf
	sed -i '/1800/d' /etc/storage/dnsmasq/dnsmasq.conf
	sed -i '/hosts_fq.conf/d' /etc/storage/dnsmasq/dnsmasq.conf
else
	echo -e "\033[41;37m 开始写入启动代码 \e[0m\n"
fi

if [ -f “/etc/storage/dnsmasq/dnsmasq.conf" ]; then
	echo "listen-address=${route_vlan},127.0.0.1
# 添加监听地址
# 开启日志选项
log-queries
log-facility=/var/log/dnsmasq.log
# 异步log,缓解阻塞，提高性能。默认为5，最大为100
log-async=50
# 缓存最长时间
#min-cache-ttl=1800
# 指定服务器'域名''地址'文件夹
conf-dir=/etc/storage/dnsmasq.d/conf
# conf-file=/etc/storage/dnsmasq.d/conf/hosts_fq.conf" >> /tmp/tmp_dnsmasq.conf
cat /tmp/tmp_dnsmasq.conf | sed -E -e "/# /d" >> /etc/storage/dnsmasq/dnsmasq.conf; sleep 3
fi

sleep 2
rm /tmp/tmp_dnsmasq rm /tmp/tmp_dnsmasq.conf
